home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / app / Desktop.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  9.6 KB  |  387 lines

  1. package com.extensibility.app;
  2.  
  3. import com.extensibility.rock.Screen;
  4. import com.extensibility.util.Evaluator;
  5. import com.extensibility.util.FilteredEnumerator;
  6. import com.extensibility.xml.URI;
  7. import java.awt.Component;
  8. import java.awt.Dimension;
  9. import java.awt.Frame;
  10. import java.awt.Point;
  11. import java.awt.Window;
  12. import java.awt.event.WindowListener;
  13. import java.io.IOException;
  14. import java.text.DateFormat;
  15. import java.util.Date;
  16. import java.util.Enumeration;
  17. import java.util.EventObject;
  18. import java.util.Hashtable;
  19. import java.util.Vector;
  20. import javax.swing.JFrame;
  21. import javax.swing.SwingUtilities;
  22.  
  23. public class Desktop extends Screen {
  24.    protected static Vector documents = new Vector();
  25.    protected static Vector windows = new Vector();
  26.    protected static HelpWindow helpWindow;
  27.    protected static Splash splash;
  28.    protected static JFrame welcome;
  29.    protected static BaseWindow frontWindow;
  30.    protected static Hashtable docWinCounter = new Hashtable();
  31.    static WindowListener windowListener = new 4();
  32.  
  33.    public static final BaseDocument getMostRecentDocument(Class var0) {
  34.       for(int var1 = documents.size() - 1; var1 >= 0; --var1) {
  35.          if (var0.isInstance(documents.elementAt(var1))) {
  36.             return (BaseDocument)documents.elementAt(var1);
  37.          }
  38.       }
  39.  
  40.       return null;
  41.    }
  42.  
  43.    public static BaseWindow getFrontDocWindow() {
  44.       return frontWindow;
  45.    }
  46.  
  47.    public static final void activateDocument(BaseDocument var0) {
  48.       if (var0 != null) {
  49.          int var1 = windows.size();
  50.          int var2 = 1;
  51.  
  52.          while(var2 < windows.size() - 1) {
  53.             BaseWindow var3 = (BaseWindow)windows.elementAt(var2);
  54.             BaseDocument var4 = var3.getDocument();
  55.             if (var4 != null && var4 != var0) {
  56.                ((Window)var3).toBack();
  57.                if (windows.removeElement(var3)) {
  58.                   windows.addElement(var3);
  59.                }
  60.  
  61.                --var1;
  62.                if (var1 == 0) {
  63.                   return;
  64.                }
  65.             } else {
  66.                ++var2;
  67.             }
  68.          }
  69.  
  70.       }
  71.    }
  72.  
  73.    public static final BaseDocument getDocument(URI var0) {
  74.       for(int var1 = 0; var1 < documents.size(); ++var1) {
  75.          if (((BaseDocument)documents.elementAt(var1)).getURI().equals(var0)) {
  76.             return (BaseDocument)documents.elementAt(var1);
  77.          }
  78.       }
  79.  
  80.       return null;
  81.    }
  82.  
  83.    public static final Enumeration getDocuments() {
  84.       return documents.elements();
  85.    }
  86.  
  87.    public static final Vector getWindows() {
  88.       return windows;
  89.    }
  90.  
  91.    public static int getDefaultDocWidth(BaseDocument var0) {
  92.       return Screen.DOC_WIDTH;
  93.    }
  94.  
  95.    public static int getDefaultDocHeight(BaseDocument var0) {
  96.       return Screen.DOC_HEIGHT;
  97.    }
  98.  
  99.    public static int getDefaultDocLeft(BaseDocument var0) {
  100.       return Screen.DOC_LEFT;
  101.    }
  102.  
  103.    protected static int getOffset() {
  104.       int var0 = 0;
  105.  
  106.       while(true) {
  107.          BaseWindow var1 = null;
  108.  
  109.          for(int var2 = 0; var1 == null && var2 < windows.size(); ++var2) {
  110.             BaseWindow var3 = (BaseWindow)windows.elementAt(var2);
  111.             int var10001 = Screen.DOC_LEFT + var0;
  112.             if (((Component)var3).getLocation().x == var10001) {
  113.                var1 = var3;
  114.             }
  115.          }
  116.  
  117.          if (var1 == null) {
  118.             return var0;
  119.          }
  120.  
  121.          var0 += 16;
  122.       }
  123.    }
  124.  
  125.    protected static Point getNextDocLoc() {
  126.       int var0 = getOffset();
  127.       return new Point(Screen.DOC_LEFT + var0, Screen.DOC_TOP + var0);
  128.    }
  129.  
  130.    public static void positionNewWindow(BaseWindow var0) {
  131.       BaseDocument var1 = var0.getDocument();
  132.       Point var2 = getNextDocLoc();
  133.       Dimension var3 = new Dimension(var1.getDefaultDocWidth(), var1.getDefaultDocHeight() - var2.y);
  134.       if (var2.x + var3.width > Screen.getScreenSize().width) {
  135.          var3.width = Screen.getScreenSize().width - var2.x - 8;
  136.       }
  137.  
  138.       if (var2.y + var3.height > Screen.getScreenSize().height) {
  139.          var3.height = Screen.getScreenSize().height - var2.y - 8;
  140.       }
  141.  
  142.       ((Component)var0).setLocation(var2);
  143.       var0.setSize(var3.width, var3.height);
  144.    }
  145.  
  146.    public static void showNewWindow(BaseWindow var0, boolean var1) {
  147.       BaseDocument var2 = var0.getDocument();
  148.       if (!var1) {
  149.          Integer var3 = (Integer)docWinCounter.get(var2);
  150.          int var4 = var3 + 1;
  151.          ((Frame)var0).setTitle(String.valueOf(String.valueOf(((Frame)var0).getTitle()).concat(String.valueOf(':'))).concat(String.valueOf(var4)));
  152.          docWinCounter.put(var2, new Integer(var4));
  153.       }
  154.  
  155.       ((Component)var0).setVisible(true);
  156.       if (var1) {
  157.          splashCleanup();
  158.          docWinCounter.put(var2, new Integer(1));
  159.       }
  160.  
  161.    }
  162.  
  163.    public static HelpWindow createHelpWindow(String var0) {
  164.       String var1 = BaseApplication.getPreferences().getBrowserPath();
  165.       if (!BaseApplication.getPreferences().getExternalHelpBrowser()) {
  166.          var1 = null;
  167.       }
  168.  
  169.       if (var1 != null) {
  170.          try {
  171.             String var10 = UI.getHelpURI(var0);
  172.             Runtime var3 = Runtime.getRuntime();
  173.             StringBuffer var4 = new StringBuffer("");
  174.             int var5 = 0;
  175.  
  176.             for(int var6 = var10.length(); var5 < var6; ++var5) {
  177.                char var7 = var10.charAt(var5);
  178.                if (var7 != ' ') {
  179.                   var4.append(var7);
  180.                } else {
  181.                   var4.append("%20");
  182.                }
  183.             }
  184.  
  185.             String[] var11 = new String[]{String.valueOf(String.valueOf('"').concat(String.valueOf(var1))).concat(String.valueOf('"')), var4.toString()};
  186.             var3.exec(var11);
  187.             Object var8 = null;
  188.             return (HelpWindow)var8;
  189.          } catch (IOException var9) {
  190.          }
  191.       }
  192.  
  193.       if (helpWindow == null) {
  194.          helpWindow = new HelpWindow(var0);
  195.          String var2 = UI.getString("help.item.index.htm");
  196.          if (var2.startsWith("#")) {
  197.             var2 = "index.html";
  198.          }
  199.  
  200.          helpWindow.setHome(var2);
  201.          helpWindow.addWindowListener(new 1());
  202.          helpWindow.setLocation(Screen.getScreenSize().width - 600 - 3, Screen.TOP_GAP);
  203.          helpWindow.setSize(600, Screen.DOC_HEIGHT);
  204.          helpWindow.setVisible(true);
  205.       } else {
  206.          helpWindow.toFront();
  207.          helpWindow.setVisible(true);
  208.          helpWindow.showPage(var0);
  209.       }
  210.  
  211.       return helpWindow;
  212.    }
  213.  
  214.    public static Splash createAboutWindow() {
  215.       Splash var0 = createSplash();
  216.       ((Window)var0).toFront();
  217.       return var0;
  218.    }
  219.  
  220.    public static void splashCleanup() {
  221.       if (splash != null) {
  222.          splash.setVisible(false);
  223.          splash.dispose();
  224.       }
  225.  
  226.    }
  227.  
  228.    public static Splash createSplash() {
  229.       if (splash == null) {
  230.          splash = new Splash();
  231.          splash.addWindowListener(new 2());
  232.          updateSplash(splash);
  233.       }
  234.  
  235.       splash.show();
  236.       return splash;
  237.    }
  238.  
  239.    public static void updateSplash(Splash var0) {
  240.       splash = var0;
  241.       String var1 = BaseApplication.getPreference("ESB");
  242.       String var2 = BaseApplication.getPreference("KKB");
  243.       String var3 = BaseApplication.getPreference("CAB");
  244.       Date var4 = BaseApplication.getExpiration();
  245.       String var5 = BaseApplication.getApplication().getVersion();
  246.       String var6 = null;
  247.       if (BaseApplication.isLaunchLimited()) {
  248.          var6 = UI.getString("splash.limit", (new Integer(BaseApplication.getLaunchesLeft())).toString());
  249.       } else if (var4 != null) {
  250.          DateFormat var7 = DateFormat.getDateInstance(2);
  251.          String var8 = var7.format(var4);
  252.          var6 = UI.getString("splash.expire", var8);
  253.       }
  254.  
  255.       splash.setInfo(var1, var2, var3, var4, var5, var6);
  256.    }
  257.  
  258.    public static void ensureWindow() {
  259.       if (windows.size() == 0) {
  260.          welcome.show();
  261.       }
  262.  
  263.    }
  264.  
  265.    public static JFrame createWelcome(boolean var0) {
  266.       if (welcome == null) {
  267.          welcome = BaseApplication.getApplication().createWelcome();
  268.       }
  269.  
  270.       if (var0) {
  271.          welcome.show();
  272.       }
  273.  
  274.       return welcome;
  275.    }
  276.  
  277.    public static JFrame getWelcome() {
  278.       return welcome;
  279.    }
  280.  
  281.    public static BaseWindow findWindow(Evaluator var0) {
  282.       Enumeration var1 = windows.elements();
  283.  
  284.       while(var1.hasMoreElements()) {
  285.          BaseWindow var2 = (BaseWindow)var1.nextElement();
  286.          if (var0.isMatch(var2)) {
  287.             return var2;
  288.          }
  289.       }
  290.  
  291.       return null;
  292.    }
  293.  
  294.    public static Enumeration getWindowsOfDocument(BaseDocument var0) {
  295.       return new FilteredEnumerator(windows.elements(), new 3(var0));
  296.    }
  297.  
  298.    public static boolean isLastWindowOfDocument(BaseWindow var0) {
  299.       BaseDocument var1 = var0.getDocument();
  300.       Enumeration var2 = windows.elements();
  301.  
  302.       while(var2.hasMoreElements()) {
  303.          BaseWindow var3 = (BaseWindow)var2.nextElement();
  304.          if (var3 != var0 && var3.getDocument() == var1) {
  305.             return false;
  306.          }
  307.       }
  308.  
  309.       return true;
  310.    }
  311.  
  312.    public static boolean isLastDocument(BaseDocument var0) {
  313.       return documents.size() == 1 && documents.elements().nextElement() == var0;
  314.    }
  315.  
  316.    public static final WindowListener getWindowListener() {
  317.       return windowListener;
  318.    }
  319.  
  320.    protected static void removeWindow(BaseWindow var0) {
  321.       windows.removeElement(var0);
  322.    }
  323.  
  324.    protected static void addWindow(BaseWindow var0) {
  325.       windows.addElement(var0);
  326.    }
  327.  
  328.    protected static void windowListChanged() {
  329.       for(int var0 = 0; var0 < windows.size(); ++var0) {
  330.          ((BaseWindow)windows.elementAt(var0)).fillWindowsMenu();
  331.       }
  332.  
  333.    }
  334.  
  335.    protected static void closingDocument(BaseDocument var0) {
  336.       documents.removeElementAt(documents.indexOf(var0));
  337.    }
  338.  
  339.    protected static void openningDocument(BaseDocument var0) {
  340.       documents.addElement(var0);
  341.    }
  342.  
  343.    public static Frame getDialogParent(EventObject var0) {
  344.       Component var1 = null;
  345.       if (var0 != null) {
  346.          var1 = var0.getSource() instanceof Component ? (Component)var0.getSource() : null;
  347.       }
  348.  
  349.       return getDialogParent(var1);
  350.    }
  351.  
  352.    public static Frame getDialogParent(Component var0) {
  353.       if (var0 == null) {
  354.          var0 = getFrontDocWindow();
  355.       }
  356.  
  357.       if (var0 == null && getWindows().size() > 0) {
  358.          var0 = (Component)getWindows().firstElement();
  359.       }
  360.  
  361.       if (var0 == null) {
  362.          var0 = welcome;
  363.       }
  364.  
  365.       if (var0 == null) {
  366.          return null;
  367.       } else if (var0 instanceof Frame) {
  368.          if (!((Component)var0).isVisible()) {
  369.             ((Component)var0).setVisible(true);
  370.          }
  371.  
  372.          return (Frame)var0;
  373.       } else {
  374.          Window var1 = SwingUtilities.windowForComponent((Component)var0);
  375.          if (var1 instanceof Frame) {
  376.             if (!((Component)var1).isVisible()) {
  377.                ((Component)var1).setVisible(true);
  378.             }
  379.  
  380.             return (Frame)var1;
  381.          } else {
  382.             return getDialogParent((Component)null);
  383.          }
  384.       }
  385.    }
  386. }
  387.